package com.gimi.cloud.bbp.manage.consumer.service.mall.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.StringUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.dto.mall.MallAppColumnDTO;
import com.gimi.cloud.bbp.manage.consumer.feign.MallFeignService;
import com.gimi.cloud.bbp.manage.consumer.service.mall.MallAppCloumnService;

/**
 * 栏目相关接口实现类
 *
 * @author wbj
 * @version 1.0
 * @Description
 * @create 2018-02-01
 **/
@Service
public class MallAppCloumnServiceImpl implements MallAppCloumnService {
    private static final Logger logger = LoggerFactory.getLogger(MallAppCloumnServiceImpl.class);
    private MallFeignService mallFeignService;

    @Autowired
    public MallAppCloumnServiceImpl(MallFeignService mallFeignService) {
        this.mallFeignService = mallFeignService;
    }

    @Override
    public Response getAppCloumnList(HttpServletRequest request, HttpServletResponse response, MallAppColumnDTO dto) throws Exception {
    	 return mallFeignService.getAppCloumnList(dto);
    }

    @Override
    public Response getAppCloumnInfo(HttpServletRequest request, HttpServletResponse response, MallAppColumnDTO dto) throws Exception {
        if(null == dto.getAclId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"栏目id为空，获取栏目信息失败");
            Util.sendResponse(JsonUtil.toJson(resp), response);
            return resp;
        }
        return mallFeignService.getAppCloumnInfo(dto);
    }

    @Override
    public Response addAppCloumn(HttpServletRequest request, HttpServletResponse response, MallAppColumnDTO dto) throws Exception {
        if(null != dto.getAclId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"栏目Id不为空，添加栏目信息失败");
            return resp;
        }
        return mallFeignService.saveOrUpdateAppCloumn(dto);
    }

    @Override
    public Response editAppCloumn(HttpServletRequest request, HttpServletResponse response, MallAppColumnDTO dto) throws Exception {
        if(null == dto.getAclId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"栏目Id为空，修改栏目信息失败");
            return resp;
        }
        return mallFeignService.saveOrUpdateAppCloumn(dto);
    }

    @Override
    public Response deleteAppCloumn(HttpServletRequest request, HttpServletResponse response, MallAppColumnDTO dto) throws Exception {
        if(null == dto.getAclId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"栏目Id为空，删除栏目信息失败");
            return resp;
        }
        return mallFeignService.deleteAppCloumn(dto);
    }

    @Override
    public Response detailList(HttpServletRequest request, HttpServletResponse response, MallAppColumnDTO dto) throws Exception {
        if(StringUtil.isBlank(dto.getQueryType())){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"栏目类型为空，获取栏目组详细信息失败");
            return resp;
        }
        return mallFeignService.detailList(dto);
    }
}
